<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/WEB-INF/views/system/taglibs.jsp" %>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<div id="toolbar">
    <form id="list" action="getData">
        <div id="search" class="easyui-panel" title="查询条件" data-options="fit:true,collapsible:true,border:0">
            <table class="searchTable">
                <tr>
                    <td>是否为精选：</td>
                    <td>
                        <select name="careChosen">
                            <option value="">请选择...</option>
                            <option value="0">否</option>
                            <option value="1">是</option>
                        </select>
                    </td>
                    <td>用户昵称或手机号：</td>
                    <td>
                        <input type="text" name="nickOrMobile">
                    </td>
                    <td>创建时间：</td>
                    <td><input id="createTimeStart" name="createTimeStart" type="datetime" class="easyui-datebox"/>
                        至 <input id="createTimeEnd" name="createTimeEnd" type="datetime" class="easyui-datebox"/>
                    </td>
                    <td>
                        <button id="queryBtn" type="button" class="button">查询</button>
                    </td>
                    <td>
                        <button id="clearBtn" type="button" class="button">清空</button>
                    </td>
                </tr>
            </table>
        </div>
    </form>
    <div class="operate">
        <div class="om-panel-header">动态列表</div>
        <div class="icon">
            <ul>
                <li>
                    <a href="#" onclick="setCareChoose(1);">
                        <span class="menu13"></span>设为精选
                    </a>
                </li>
                <li>
                    <a href="#" onclick="setCareChoose(0);">
                        <span class="menu13"></span>取消精选
                    </a>
                </li>
                <li><a href="#" onclick="showEdit('/circle/detail','id',500,'90%');"><span class="menu13"></span>详情</a></li>
                <li><a href="#" onclick="removeRow('id');"><span class="menu11"></span>删除</a></li>
            </ul>
        </div>
    </div>
</div>
<table id="grid" data-options="fit:true,border:false"></table>
</body>
<script type="text/javascript">
    $(function () {
        $('#grid').datagrid({
            url: 'getData',
            pageSize: 15,
            pageList: [15, 30, 50],
            striped: true,
            rownumbers: true,
            pagination: true,
            singleSelect: false,
            toolbar: '#toolbar',
            nowrap: false,
            columns: [
                [
                    {field: 'ck', checkbox: true},
                    {
                        title: '图片', field: 'images',
                        formatter: function (v, r) {
                            var image;
                            if (v) {
                                if (v.indexOf(",")) {
                                    image = v.split(",")[0];
                                } else {
                                    image = v;
                                }
                                return '<img src="' + image + '" style="height: 100px"/>';
                            } else {
                                return "";
                            }
                        }
                    },
                    {title: '用户昵称', field: 'nick'},
                    {title: '地区', field: 'address', sortable: "true"},
                    {
                        title: '发布日期', field: 'createTime', sortable: "true",
                        formatter: function (v, r) {
                            console.log(r);
                            return new Date(r.createTime).toLocaleString();
                        }
                    },
                    {title: '点赞数', field: 'likeCount', sortable: "true"},
                    {title: '评论数', field: 'commentCount', sortable: "true"},
                    {
                        title: '是否带轨迹', field: 'pathid',
                        formatter: function (v, r) {
                            if (v) {
                                return '是';
                            } else {
                                return "否";
                            }
                        }
                    },
                    {
                        title: '是否为精选', field: 'careChosen',
                        formatter: function (v, r) {
                            if (v) {
                                return '是';
                            } else {
                                return "否";
                            }
                        }
                    },
                    {title: '话题', field: 'topics', sortable: "true"}
                ]
            ]
        });
    });


    function setCareChoose(type) {
        var selections = $('#grid').datagrid('getSelections');
        if (selections.length == 0) {
            $.messager.alert('提示:', '请至少选择一行记录');
            return false;
        }
        $.messager.confirm('提示:', '你确认要设置为精选吗?', function (e) {
            if (e) {
                var ids = [];
                for (var i = 0; i < selections.length; i++) {
                    ids.push(selections[i]['id']);
                }
                $.post('setCareChoose', {"ids": ids.toString(), "type": type}, function (data) {
                    if (data.success) {
                        $("#grid").datagrid('reload');
                        refleshTree && ($("#navtree").tree('reload'));
                        $.messager.show({
                            title: '温馨提示:',
                            msg: '设置成功!',
                            timeout: 1500,
                            showType: 'slide'
                        });
                    } else {
                        if (data.msg) {
                            $.messager.alert('提示:', data.msg, 'warning');
                        }
                    }
                }, 'json');
            }
        });

    }
</script>
</html>